package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * @author leiwenwei
 * @date 2017/10/25
 *
 * @ServletComponentScan注解后，Servlet、Filter、Listener
 * 可以直接通过 @WebServlet、@WebFilter、@WebListener 注解自动注册，无需其他代码。
 */
@SpringBootApplication
@ServletComponentScan
@EnableScheduling
public class StartSpringApplication extends SpringBootServletInitializer {

	/**
	 * 创建ServletInitializer.java，继承SpringBootServletInitializer ，
	 * 覆盖configure()，把启动类Application注册进去。
	 * 外部web应用服务器构建Web Application Context的时候，会把启动类添加进去。
	 * @param application
	 * @return
	 */
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(StartSpringApplication.class);
	}

	public static void main(String[] args) {
		SpringApplication.run(StartSpringApplication.class, args);
	}
}
